knitr::opts_chunk$set(echo = FALSE)
R tools such as dplyr and tidyr can be used to summarise data (e.g. add rain observations to obtain monthly and annual cumulative amounts). The three libraries are first loaded.
library(aimsir17) library(dplyr) library(tidyr)
Next, we show the overall data set (219,000 observations)
observations
We can confirm the number of records gathered for each month, and show these
observations %>% group_by(station, month) %>% summarise(TotalObservations=n()) %>% pivot_wider(names_from = month,values_from = TotalObservations) %>% print(n=25)
We can also confirm the number of missing rainfall values for each month.
observations %>% group_by(station, month) %>% summarise(TotalMissing=sum(is.na(rain))) %>% pivot_wider(names_from = month,values_from = TotalMissing) %>% print(n=25)
We can sum all the rainfall values for each station by each month
observations %>% group_by(station, month) %>% summarise(TotalRainfall=sum(rain,na.rm = T)) %>% pivot_wider(names_from = month,values_from = TotalRainfall) %>% print(n=25)
Order the months from driest to wettest
observations %>% group_by(month) %>% summarise(TotalRainfall=sum(rain,na.rm = T)) %>% arrange(TotalRainfall) %>% print(n=12)
Finally, order the weather stations from driest to wettest, with an index value where 100 is the wettest for 2017 (Newport!)
observations %>% group_by(station) %>% summarise(TotalRainfall=sum(rain,na.rm = T)) %>% arrange(TotalRainfall) %>% mutate(Index=100*TotalRainfall/max(TotalRainfall)) %>% print(n=25)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.